﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Liger.Web.UI
{
    public class GridColumnEditorBuilder
    {
        private readonly GridColumnEditor editor;
        public GridColumnEditorBuilder(GridColumnEditor editor)
        {
            this.editor = editor;
        }

        public GridColumnEditorBuilder Type(string type)
        {
            this.editor.Type = type;
            return this;
        }

        /// <summary>
        /// 文本框编辑器
        /// </summary>
        /// <returns></returns>
        public GridColumnEditorBuilder Textbox()
        {
            this.editor.Type = "text";
            this.editor.MinValue = null;
            this.editor.MaxValue = null;
            this.editor.ValueColumnName = null;
            this.editor.DisplayColumnName = null;
            this.editor.Data = null;
            return this;
        }

        /// <summary>
        /// 设置属性
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder Set(string property, object value)
        {
            this.editor.Options.Add(property, value);
            return this;
        }

        /// <summary>
        /// 可调整数字编辑器
        /// </summary>
        /// <returns></returns>
        public GridColumnEditorBuilder Spinner()
        {
            return Spinner(null, null);
        }
        /// <summary>
        /// 可调整数字编辑器
        /// </summary>
        /// <param name="min">最小值</param>
        /// <param name="max">最大值</param>
        /// <returns></returns>
        public GridColumnEditorBuilder Spinner(int? min,int? max)
        {
            this.editor.Type = "spinner";
            this.editor.MinValue = min;
            this.editor.MaxValue = max;
            this.editor.ValueColumnName = null;
            this.editor.DisplayColumnName = null;
            this.editor.Data = null;
            return this;
        }
        /// <summary>
        /// 日期编辑器
        /// </summary>
        /// <returns></returns>
        public GridColumnEditorBuilder Date()
        {
            this.editor.Type = "date";
            this.editor.MinValue = null;
            this.editor.MaxValue = null;
            this.editor.ValueColumnName = null;
            this.editor.DisplayColumnName = null;
            this.editor.Data = null;
            return this;
        }
        /// <summary>
        /// 复选框编辑器
        /// </summary>
        /// <returns></returns>
        public GridColumnEditorBuilder Checkbox()
        {
            this.editor.Type = "checkbox";
            this.editor.MinValue = null;
            this.editor.MaxValue = null;
            this.editor.ValueColumnName = null;
            this.editor.DisplayColumnName = null;
            this.editor.Data = null;
            return this;
        }

        /// <summary>
        /// 下拉框编辑器
        /// </summary> 
        /// <returns></returns>
        public GridColumnEditorBuilder Select()
        {
            return Select(null, null, null);
        }

         /// <summary>
        /// 下拉框编辑器
         /// </summary>
         /// <param name="data"></param>
         /// <returns></returns>
        public GridColumnEditorBuilder Select(object data)
        {
            return Select(null, null, data);
        }
        /// <summary>
        /// 下拉框编辑器
        /// </summary>
        /// <param name="ValueColumnName"></param>
        /// <param name="DisplayColumnName"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder Select(string ValueColumnName, string DisplayColumnName)
        {
            return Select(ValueColumnName, DisplayColumnName, null);
        }

        /// <summary>
        /// 下拉框编辑器
        /// </summary>
        /// <param name="ValueColumnName"></param>
        /// <param name="DisplayColumnName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder Select(string ValueColumnName, string DisplayColumnName,object data)
        {
            this.editor.Type = "combobox";
            this.editor.MinValue = null;
            this.editor.MaxValue = null;
            this.editor.ValueColumnName = ValueColumnName;
            this.editor.DisplayColumnName = DisplayColumnName;
            this.editor.Data = data;
            return this;
        }
        /// <summary>
        /// 设置数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder Data(object data)
        {
            this.editor.Data = data;
            return this;
        }


        /// <summary>
        /// 改变值事件
        /// </summary>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder OnChange(string functionName)
        {
            this.editor.OnChange = () => functionName;
            return this;
        }
        /// <summary>
        /// 已经改变值事件
        /// </summary>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder OnChanged(string functionName)
        {
            this.editor.OnChanged = () => functionName;
            return this;
        }

        /// <summary>
        /// 参数构造函数
        /// </summary>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder P(string functionName)
        {
            this.editor.P = () => functionName;
            return this;
        }

        /// <summary>
        /// 改变值事件
        /// </summary>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder OnChange(Func<string> function)
        {
            this.editor.OnChange = function;
            return this;
        }
        /// <summary>
        /// 已经改变值事件
        /// </summary>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder OnChanged(Func<string> function)
        {
            this.editor.OnChanged = function;
            return this;
        }

        /// <summary>
        /// 参数构造函数
        /// </summary>
        /// <param name="functionName"></param>
        /// <returns></returns>
        public GridColumnEditorBuilder P(Func<string> function)
        {
            this.editor.P = function;
            return this;
        } 
        
    }
}
